﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyKTVUtils;
using MyKTVService;

namespace MyKTV02
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }
        AdminService Aservice = new AdminService();
        private void button1_Click(object sender, EventArgs e)
        {
            if (jump) {
                ToMain();
            } else {
                bool result= Aservice.DoLogin(this.txtLoginName.Text, this.txtPassWord.Text);
                if (result)
                {
                    ToMain();
                }
                else {
                    MessageBox.Show("账号密码不正确");
                }
                
            }
        }

        private void ToMain()
        {
                frmMain frm = new frmMain();
                this.Hide();
                frm.Show();
        }
        
        /// <summary>
        /// 业务层对象
        /// </summary>
        private Service serivce = new Service();
        private bool jump=false;

        /// <summary>
        /// 绑定7天免登录用户
        /// </summary>
        private void BindCboValue()
        {
            //调用业务层查询记住密码账户
            List<Dictionary<string, object>> list = serivce.GetRemenber();
            if(list !=null && list.Count == 1)
            {
                StaticParam.LoginName = list[0]["admin_name"].ToString();
                this.txtLoginName.Text= list[0]["admin_name"].ToString();
                this.txtPassWord.Text = list[0]["admin_pwd"].ToString();
                this.ckbRemenb.Checked = true;
                jump = true;
            }
        }
        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmLogin_Load(object sender, EventArgs e)
        {
            BindCboValue();
            MessageBox.Show(MACAdress.getThisMAC().ToString());
        }

        private void frmLogin_Shown(object sender, EventArgs e)
        {

        }
    }
}
